#region

using System;
using System.ComponentModel.DataAnnotations;
using ThuySan.Bussiness;

#endregion

namespace ThuySan.Models
{
    [Serializable]
    public class SettingModel
    {
        #region Constructor

        public SettingModel()
        {
        }

        public SettingModel(Setting value)
        {
            SettingId = value.SettingId;
            Name = value.Name;
            Description = value.Description;
            Value = value.Value;
            IsUpload = value.IsUpload ?? false;
        }

        #endregion

        #region Fields

        private String _Description;

        private Boolean _IsUpload;

        private String _Name;

        private Int32 _SettingId;

        private String _Value;

        #endregion

        #region Properties

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Int32 SettingId
        {
            get { return _SettingId; }
            set { _SettingId = value; }
        }

        //[NotChanged]
        [Required(ErrorMessage = "Value is required"), StringLength(200, ErrorMessage = "Value must be under 200 characters")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
            public String Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        [StringLength(500, ErrorMessage = "Value must be under 500 characters")]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
            public String Description
        {
            get { return _Description; }
            set { _Description = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        [StringLength(500, ErrorMessage = "Value must be under 500 characters")]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
            public String Value
        {
            get { return _Value; }
            set { _Value = value; }
        }

        //[NotChanged]
        //[Required(ErrorMessage = "Value is required")]
        //[Range(0, 0, ErrorMessage = "Value must be between 0 and 0")]
        //[StringLength(0)]
        //[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email address is not valid")]
        public Boolean IsUpload
        {
            get { return _IsUpload; }
            set { _IsUpload = value; }
        }

        #endregion

        #region Operators

        public void Update(Setting value)
        {
            //value.SettingId = SettingId;
            value.Name = Name;
            value.Description = Description;
            //value.Value = Value;
            //value.IsUpload = IsUpload;
        }

        public static implicit operator SettingModel(Setting obj)
        {
            return new SettingModel(obj);
        }

        public static implicit operator Setting(SettingModel obj)
        {
            Setting value = new Setting();
            obj.Update(value);
            return value;
        }

        #endregion
    }
}
